package model

import (
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/sqlc"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

var _ PmsSkuImagesModel = (*customPmsSkuImagesModel)(nil)

type (
	// PmsSkuImagesModel is an interface to be customized, add more methods here,
	// and implement the added methods in customPmsSkuImagesModel.
	PmsSkuImagesModel interface {
		pmsSkuImagesModel
		FindSkuImagesBySkuId(ctx context.Context, skuId int64) ([]*PmsSkuImages, error)
	}

	customPmsSkuImagesModel struct {
		*defaultPmsSkuImagesModel
	}
)

func (c *customPmsSkuImagesModel) FindSkuImagesBySkuId(ctx context.Context, skuId int64) ([]*PmsSkuImages, error) {
	query := fmt.Sprintf("select %s from %s where `sku_id` = ? limit 1", pmsSkuImagesRows, c.table)
	var resp []*PmsSkuImages
	err := c.conn.QueryRowsCtx(ctx, &resp, query, skuId)
	switch err {
	case nil:
		return resp, nil
	case sqlc.ErrNotFound:
		return nil, ErrNotFound
	default:
		return nil, err
	}
}

// NewPmsSkuImagesModel returns a model for the database table.
func NewPmsSkuImagesModel(conn sqlx.SqlConn) PmsSkuImagesModel {
	return &customPmsSkuImagesModel{
		defaultPmsSkuImagesModel: newPmsSkuImagesModel(conn),
	}
}
